<?php

declare(strict_types=1);

namespace app\command;

use app\admin\jobs\MarketSMCopywritingGeneration;
use app\admin\jobs\InitTranslation;
use app\admin\jobs\MarketSMCopywritingPublish;

use app\admin\jobs\ProductProfitInit;
use app\admin\jobs\SendMailFromCart;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;


class queue extends Command
{
    /**
     * 配置参数 需要其他参数 自行添加
     * @return void
     * 2024-11-14 14 47 43
     * author: jiang
     */
    protected function configure()
    {
        // 指令配置
        $this->setName('queue')
            ->addArgument('name', Argument::OPTIONAL, "your name")
            ->addOption('lang', null, Option::VALUE_REQUIRED, '语言')
            ->setDescription('the queue command');
    }

    /**
     * 队列switch 需要执行的后续自己添加
     * command示例 : php think queue newPublish
     * @param Input $input
     * @param Output $output
     * @return void
     * 2024-11-14 13 39 42
     * author: jiang
     */
    protected function execute(Input $input, Output $output)
    {
        $name = $input->getArgument('name');
        switch ($name) {
            case 'newPublish': // 发布社媒文案到社媒平台 (已弃用)
                $handle = new MarketSMCopywritingPublish();
                $handle->execute();
                break;
            case 'createCopywriting': // 创建社媒文案 (已弃用)
                $handle = new MarketSMCopywritingGeneration();
                $handle->execute();
                break;
            case 'productProfitInit': // 初始化产品利润 
                $handle = new ProductProfitInit();
                $handle->execute();
                break;
            case 'sendMailFromCart': // 发送邮件到购物车 
                $handle = new SendMailFromCart();
                $handle->execute();
                break;
            case 'initTranslation': // 初始化翻译 
                $handle = new InitTranslation();
                if ($input->hasOption('lang')) {
                    $handle->handleTranslation($input->getOption('lang'));
                } else {
                    $handle->translation();
                }
                break;
            default:
                echo '参数错误 ', "\n";
        }
    }
}
